/**   
* TODO 
* @author zhanghui   
* @date 2016年4月20日 下午6:47:40  
*/
package com.nebula.upms.service.biz.impl;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

import com.nebula.common.datasource.mybatis.pager.DataPager;
import com.nebula.common.datasource.mybatis.pager.Pager;
import com.nebula.upms.service.biz.SessionService;
import com.nebula.upms.service.model.po.UpmsStaffSessionLogPO;
import com.nebula.upms.service.model.po.UpmsStaffSessionLogPOExample;
import com.nebula.upms.service.model.po.UpmsStaffSessionPO;
import com.nebula.upms.service.model.po.UpmsStaffSessionPOExample;
import com.nebula.upms.service.support.datasource.UpmsDs;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.nebula.common.framework.BaseService;


/** 
* TODO
* @author zhanghui
* @date 2016年4月20日 下午6:47:40  
*/
@Service("sessionService")
@Transactional
public class SessionServiceImpl extends BaseService implements SessionService {

	/**
	* Description:
	* @param params
	* @param pager
	* @return
	**/
	@Override
	public DataPager<UpmsStaffSessionPO> getStaffSessionListForPager(Map<String, Object> params, Pager pager) {
		UpmsStaffSessionPOExample example=new UpmsStaffSessionPOExample();
		UpmsStaffSessionPOExample.Criteria c= example.createCriteria();
		if(null!=params.get("loginName")){
			c.andLoginNameLike(params.get("loginName")+"%");
		}
		if(null!=params.get("personName")){
			c.andLoginNameLike(params.get("personName")+"%");
		}
		example.setOrderByClause(" login_time desc");
		
		DataPager<UpmsStaffSessionPO> dp= UpmsDs.instance().mybatis().ds().mapper().selectDataPager(example,pager);
		
		return dp;
	}

	/**
	* Description:
	* @param params
	* @param pager
	* @return
	**/
	@Override
	public DataPager<UpmsStaffSessionLogPO> getStaffSessionLogListForPager(Map<String, Object> params, Pager pager) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		UpmsStaffSessionLogPOExample example=new UpmsStaffSessionLogPOExample();
		UpmsStaffSessionLogPOExample.Criteria c=example.createCriteria();
		if(null!=params.get("loginName")){
			c.andLoginNameLike(params.get("loginName")+"%");
		}
		if(null!=params.get("personName")){
			c.andLoginNameLike(params.get("personName")+"%");
		}
		if(null!=params.get("personName")){
			c.andLoginNameLike(params.get("personName")+"%");
		}
		
		if(null!=params.get("startTime")){
			try {
				Date start=sdf.parse(params.get("startTime").toString());
				c.andLoginTimeGreaterThan(start.getTime());
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}
		if(null!=params.get("endTime")){
			try {
				Date end=sdf.parse(params.get("endTime").toString());
				c.andLoginTimeLessThan(end.getTime());
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}
		
		example.setOrderByClause(" login_time desc");
		DataPager<UpmsStaffSessionLogPO> dp=UpmsDs.instance().mybatis().ds().mapper().selectDataPager(example,pager);
		
		return dp;
	}

	/**
	* Description:
	* @return
	**/
	@Override
	public int getStaffSessionCount() {
		UpmsStaffSessionPOExample example=new UpmsStaffSessionPOExample();
		int count=(int)UpmsDs.instance().mybatis().ds().mapper().countByExample(example);
		
		return count;
	}


	
}
